<?php
	include_once 'index.model.php';
	
	class Evenement {
		private $numEvent;
		private $nom;
		private $dateEvent;
		private $sujet;
		private $organisateur;



		public static function getEvenement($numEvent)
		{
			$connexion = connexion();
			$res = array();
			$select = $connexion->prepare('SELECT * FROM evenement e WHERE e.numEvent = ?') or die(print_r($connexion->errorInfo()));
			$select->execute(array($numEvent));

			while($enregistrement = $select->fetch(PDO::FETCH_OBJ))
			{
				$res =new Evenement($enregistrement->numEvent, $enregistrement->nom, $enregistrement->dateEvent, $enregistrement->sujet, $enregistrement->organisateur);
			}
			
			return $res;
		}


		public static function ajoutEvenement($Evenement)
		{
			$connexion = connexion();
			$res = array();
			$select = $connexion->prepare('INSERT INTO evenement (numEvent, nom, dateEvent, sujet, organisateur) VALUES (?, ?, ?, ?, ?)') or die(print_r($connexion->errorInfo()));
			$select->execute(array($Evenement->getNumEvent(),$Evenement->getNom(),$Evenement->getDateEvent(),$Evenement->getSujet(),$Evenement->getOrganisateur()));
		}


		public function __construct($numEvent, $nom, $dateEvent, $sujet, $organisateur)
		{
			$this->numEvent = $numEvent;
			$this->nom = $nom;
			$this->dateEvent = $dateEvent;
			$this->sujet = $sujet;
			$this->organisateur = $organisateur;
		}

		public function getNom()
		{
			return $this->nom;
		}

		public function getDateEvent()
		{
			return $this->dateEvent;
		}
		
		public function getNumEvent()
		{
			return $this->numEvent;
		}

		public function getSujet()
		{
			return $this->sujet;
		}

		public function getOrganisateur()
		{
			return $this->Organisateur;
		}




		public function setNom($nom)
		{
			$this->nom = $nom;
		}

		public function setDateEvent($dateEvent)
		{
			$this->dateEvent = $dateEvent;
		}
		
		public function setNumEvent($numEvent)
		{
			$this->numEvent = $numEvent;
		}

		public function setSujet($sujet)
		{
			$this->sujet = $sujet;
		}

		public function setOrganisateur($organisateur)
		{
			$this->organisateur = $organisateur;
		}


		public function setInfosEvenement()
		{
			$connexion = connexion();
			$res = array();
			$select = $connexion->prepare('UPDATE evenement SET numEvent=?, nom=?, dateEvent=?, sujet=?, organisateur=? WHERE numEvent = ?') or die(print_r($connexion->errorInfo()));
			$select->execute(array($this->numEvent, $this->nom, $this->dateEvent, $this->sujet, $this->organisateur, $this->numEvent));
		}
	}
?>